package tokens;

import java.util.ListIterator;
import java.util.Queue;
import java.util.Stack;

import parser.ParserException;
import nodes.AbstractNode;
import nodes.binary.DivideNode;


/**
 * A division token
 * @author Charlie Hatcher
 * @author Roman Zhang
 */
public class DivideToken extends AbstractBinaryToken
{
	private static final String DIVIDE_TOKEN = "\\/";

    public DivideToken ()
    {
        precedence = 1;
    }

	@Override
	public AbstractNode process() {
		return new DivideNode(myModel);
	}


	@Override
	public boolean matchToken(String str, ListIterator<String> it) {
		return str.matches(DIVIDE_TOKEN);
	}
	 public String toString ()
	    {
	        return syntaxBundle.getString("division_label");
	    }

	@Override
	public void handleParser(String str, ListIterator<String> it,
			Stack<AbstractBinaryToken> opStack,
			Queue<AbstractNode> outPutQueue, Queue<AbstractNode> queue)
			throws Exception {
		if(!outPutQueue.isEmpty()){
			AbstractNode temp = outPutQueue.poll();
			outPutQueue.add(new DivideToken().process());
			outPutQueue.add(temp);
		}
		else throw ParserException.BAD_SYNTAX; 
	    }
		
	


}